import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/public/el-form.vue"; //弹框form

import {
    resettingSampleWork, //报验-保存
} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
    ],
    data() {
        return {
            visible: "",
            loading: false,
            isLock: false, //保存按钮是否可编辑
            dialogHeight: null,
            title: "",
            formData: {
                fId: "", // 申请单fid //为空判断为新增
                fStatus: "", //状态
                userId: "", // 当前登录人id
                userName: "", // 当前登录人姓名
            },
            formObj: formJs.formObj, //报验信息

            btnShow: true,
            newRow: null,

        };
    },
    components: {
        publicForm,
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },

        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },

        statusNum: {
            handler(newVal) {
                if (newVal) {
                    // this.edit();
                }
            },
            immediate: true,
        },

        currentRow: {
            handler(newVal) {
                this.newRow = newVal;
                this.edit();
            },
            deep: true,
            immediate: true,
        },

    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {

        this.getHeight();

    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.25 + "px";
        },
        closeDialog() {
            this.$emit("close");
        },
        selectChange(data, a, b) {
            console.log("selectChange", data, a, b);
        },
        edit() {
            this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
            this.formData = this.$options.data.call(this).formData;

            this.btnShow = true;
            this.formData = {
                fId: this.newRow.fId, // 申请单fid //为空判断为新增
                fStatus: "",//退回状态
                userId: this.userInfo.userId, // 当前登录人id
                userName: this.userInfo.realName, // 当前登录人姓名
            }

        },
        yj_saveForm() {
            if (this.$refs.publicForm0.submitForm()) {
                // console.log(this.formData);
                this.saveForm(this.formData);
            } else {
                console.log("error");
            }
        },
        // 保存
        saveForm(obj) {
            this.loading = true;
            this.isLock = true;
            resettingSampleWork(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = false;
                        this.visible = false;
                        this.$emit("refreshList");
                        this.$message.success({
                            content: "保存成功",
                            duration: 1000
                        });
                        this.isLock = false
                    } else {
                        this.loading = false;
                        this.isLock = false;
                        this.$message.error({
                            content: "保存失败"+res.msg,
                            duration: 1000
                        });
                    }
                })
                .catch((error) => {
                    console.log("报验保存接口", error);
                });
        },
    },
};